package com.zg.scf.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zg.common.core.R;
import com.zg.common.core.util.DateUtil;
import com.zg.scf.domain.convert.RuleConvert;
import com.zg.scf.domain.req.rule.RuleAddReq;
import com.zg.scf.domain.req.rule.RulePageReq;
import com.zg.scf.domain.req.rule.RuleStateEditReq;
import com.zg.scf.domain.vo.ConfCompanyVo;
import com.zg.scf.service.RuleService;
import com.zg.scf.enm.DirectionEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>Description: </p>
 *
 * @author zhanfeng.liang
 * @since 2025/5/22 10:54
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/scf/confCompany")
@Slf4j
@Api(tags = "企业配置管理")
public class RuleController {
    private final RuleService RuleService;

    private final RuleConvert RuleConvert;

    @PostMapping("/pageWhite")
    public R<Page<ConfCompanyVo>> pageWhite( @RequestBody RulePageReq pageReq) {
        pageReq.setDirection(DirectionEnum.POSITIVE.getValue());
        Page<ConfCompanyVo> page = RuleService.pageInfo(pageReq,ConfCompanyVo.class);
        return R.success(page);
    }

    @PostMapping("/pageBlack")
    public R<Page<ConfCompanyVo>> pageBlack( @RequestBody  @Valid RulePageReq pageReq) {
        pageReq.setDirection(DirectionEnum.NEGATIVE.getValue());
        Page<ConfCompanyVo> page = RuleService.pageInfo(pageReq,ConfCompanyVo.class);
        return R.success(page);
    }


    @PostMapping("/addWhite")
    @ApiOperation(value = "添加白名单")
    public R add(  @RequestBody @Valid RuleAddReq addReq) {
        addReq.setDirection(DirectionEnum.POSITIVE.getValue());
        addReq.setEndTime(DateUtil.getToEndOfDay(addReq.getEndTime()));
        RuleService.add(addReq);
        return R.success();
    }

    @PostMapping("/addBlack")
    public R addBlack(@RequestBody @Valid RuleAddReq addReq) {
        addReq.setEndTime(DateUtil.getToEndOfDay(addReq.getEndTime()));
        addReq.setDirection(DirectionEnum.NEGATIVE.getValue());
        RuleService.add(addReq);
        return R.success();
    }

    @PostMapping("/editState")
    @ApiOperation(value = "修改状态")
    public R editState(@RequestBody @Valid RuleStateEditReq editReq) {
        RuleService.editState(editReq);
        return R.success();
    }

}
